package com.yoda.youdianda;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.yoda.youdianda.properties.OssProperties;
import com.yoda.youdianda.template.OssTemplate;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author shawn
 * @date 2022年 11月 12日 19:47
 */
@MapperScan("com.yoda.youdianda.mapper")
@SpringBootApplication
@EnableTransactionManagement//开启事务管理
@EnableConfigurationProperties(OssProperties.class)
//@EnableMPP
public class YodaApplication {
    public static void main(String[] args) {
        SpringApplication.run(YodaApplication.class,args);
    }

    /**
     * mybatis +拦截器
     * 分页插件
     * @return {@link MybatisPlusInterceptor}
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @Bean
    public OssTemplate ossTemplate(OssProperties ossProperties){
        return new OssTemplate(ossProperties);
    }
}
